package com.zz.parkingsystem.controller.admin;

import com.zz.parkingsystem.dto.SectionDTO;
import com.zz.parkingsystem.entity.Section;
import com.zz.parkingsystem.service.SectionService;
import com.zz.parkingsystem.util.Result;
import com.zz.parkingsystem.util.ResultGenerator;
import com.zz.parkingsystem.vo.PageResult;
import io.swagger.annotations.*;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author wangyuxiang
 */
@Api(tags = "路段请求")
@RestController
@RequestMapping("/adminSection")
public class AdminSectionController {
    @Resource
    private SectionService sectionService;


    @PostMapping("/queryAllSectionMessage")
    @ApiOperation("查询路段管理页面所有数据")
    @ApiParam(name = "SectionDTO", value = "")
    public Result queryAllSectionMessage(@RequestBody SectionDTO sectionDTO) {
        PageResult list = sectionService.queryAllSectionMessage(sectionDTO);
        return ResultGenerator.genSuccessResult(list);
    }

    @PostMapping("/addSection")
    @ApiOperation("添加路段数据")
    @ApiParam(name = "SectionDTO", value = "")
    public Result addSection(@RequestBody SectionDTO sectionDTO) {
        sectionService.addSection(sectionDTO);
        return ResultGenerator.genSuccessResult();
    }


    @GetMapping("/queryAllIns")
    @ApiOperation("查询巡检员")
    @ApiParam(name = "无参数")
    public Result queryAllIns() {
        List list = sectionService.queryAllIns();
        return ResultGenerator.genSuccessResult(list);
    }


    @GetMapping("/selInsById/{id}")
    @ApiOperation("根据id查询路段")
    @ApiParam(value = "id", name = "路段id")
    public Result selInsById(@PathVariable("id") Integer id) {
        Section section = sectionService.selectByPrimaryKey(id.longValue());
        return ResultGenerator.genSuccessResult(section);
    }


//修改路段
    @PutMapping("/updateSection")
    @ApiOperation("根据id修改路段")
    @ApiParam(value = "id", name = "路段id")
    public Result updateSection(@RequestBody Section section) {
        int i = sectionService.updateByPrimaryKeySelective(section);
        if (i>0){
            return ResultGenerator.genSuccessResult();
        }else {
            return ResultGenerator.genFailResult();
        }
    }

}
